﻿using System;
using System.ComponentModel;
using System.Diagnostics;

namespace Helper
{
    public abstract class ViewModelBase : IViewModelBase, IDisposable
    {
        string title;
        public ViewModelBase()
        {
            Title = "";
        }
        public void Dispose()
        {
            Reset();
        }
        public event PropertyChangedEventHandler PropertyChanged;
        
        protected void NotifyPropertyChanged(string propertyName) 
        { 
            this.VerifyPropertyName(propertyName); PropertyChangedEventHandler handler = this.PropertyChanged; 
            if (handler != null) { var e = new PropertyChangedEventArgs(propertyName); handler(this, e); } 
        }

        [DebuggerStepThrough]
        private void VerifyPropertyName(string propertyName)
        {
            if (TypeDescriptor.GetProperties(this)[propertyName] == null)
            {
                string msg = "Invalid property name: " + propertyName;
                Debug.Fail(msg);
            }
        }
        
        protected abstract void InitVars();

        protected abstract void CreateCommands();

        public abstract void Reset();

        public string Title
        {
            get { return title; }
            set
            {
                if (value != this.title)
                {
                    this.title = value;
                    NotifyPropertyChanged("Title");
                }
            }
        }
       
    }

    public interface IViewModelBase: INotifyPropertyChanged
    {
        string Title
        { get; set; }

        void Reset();
    }
}
